/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ManageHousesPanel.java
 *
 * Created on 17.Kas.2009, 14:32:42
 */

package fairhelper.panels;

import fairhelper.HouseManager;
import fairhelper.UserManager;
import fairhelper.language.Language;
import fairhelper.theme.Theme;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 *
 * @author Feoran
 */
public class ManageHousesPanel extends javax.swing.JPanel {

    private ManageHousesMainPanel manageHousesMainPanel;
    private ManagePeopleMainPanel managePeopleMainPanel;
    private AddHousePanel addHousePanel;
    private AddPersonPanel addPersonPanel;
    private UpdateHousePanel updateHousePanel;
    private UpdatePersonPanel updatePersonPanel;
    private HouseHelpFinderPanel houseHelpFinderPanel;
    private PersonHelpFinderPanel personHelpFinderPanel;

    /** Creates new form ManageHousesPanel */
    public ManageHousesPanel() {
        initComponents();
        manageHousesPanelButtonActionPerformed(null);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        manageHousesPanelButton = new javax.swing.JButton();
        addHousePanelButton = new javax.swing.JButton();
        addPersonPanelButton = new javax.swing.JButton();
        manageHousesScrollPane = new javax.swing.JScrollPane();

        setBackground(Theme.getColor("backgroundColor1"));
        setPreferredSize(new java.awt.Dimension(800, 480));

        jPanel1.setBackground(Theme.getColor("backgroundColor1"));
        jPanel1.setPreferredSize(new java.awt.Dimension(180, 480));

        manageHousesPanelButton.setBackground(Theme.getColor("backgroundColor2"));
        manageHousesPanelButton.setForeground(Theme.getColor("labelColor1"));
        manageHousesPanelButton.setText(Language.getText("manageHousesPanelButton"));
        manageHousesPanelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                manageHousesPanelButtonActionPerformed(evt);
            }
        });

        addHousePanelButton.setBackground(Theme.getColor("backgroundColor2"));
        addHousePanelButton.setForeground(Theme.getColor("labelColor1"));
        addHousePanelButton.setText(Language.getText("addHousePanelButton"));
        addHousePanelButton.setEnabled(UserManager.getManageHousePrivilage());
        addHousePanelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addHousePanelButtonActionPerformed(evt);
            }
        });

        addPersonPanelButton.setBackground(Theme.getColor("backgroundColor2"));
        addPersonPanelButton.setForeground(Theme.getColor("labelColor1"));
        addPersonPanelButton.setText(Language.getText("addPersonPanelButton"));
        addPersonPanelButton.setEnabled(UserManager.getManageHousePrivilage());
        addPersonPanelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addPersonPanelButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(addHousePanelButton, javax.swing.GroupLayout.DEFAULT_SIZE, 156, Short.MAX_VALUE)
                    .addComponent(manageHousesPanelButton, javax.swing.GroupLayout.DEFAULT_SIZE, 156, Short.MAX_VALUE)
                    .addComponent(addPersonPanelButton, javax.swing.GroupLayout.DEFAULT_SIZE, 156, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(127, 127, 127)
                .addComponent(manageHousesPanelButton)
                .addGap(18, 18, 18)
                .addComponent(addHousePanelButton)
                .addGap(18, 18, 18)
                .addComponent(addPersonPanelButton)
                .addContainerGap(242, Short.MAX_VALUE))
        );

        manageHousesScrollPane.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(manageHousesScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 614, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(manageHousesScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 400, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void addHousePanelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addHousePanelButtonActionPerformed
        manageHousesMainPanel = null;
        addPersonPanel = null;
        updateHousePanel = null;
        managePeopleMainPanel = null;
        addHousePanel = new AddHousePanel();
        manageHousesScrollPane.setViewportView(addHousePanel);
        manageHousesScrollPane.revalidate();
        manageHousesScrollPane.repaint();
        addHousePanel.getAddHousePanelBackButton().addActionListener(new AddHousePanelBackButton());
    }//GEN-LAST:event_addHousePanelButtonActionPerformed

    private void manageHousesPanelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_manageHousesPanelButtonActionPerformed
        addHousePanel = null;
        addPersonPanel = null;
        updateHousePanel = null;
        managePeopleMainPanel = null;
        updatePersonPanel = null;
        manageHousesMainPanel = new ManageHousesMainPanel();
        manageHousesScrollPane.setViewportView(manageHousesMainPanel);
        manageHousesScrollPane.revalidate();
        manageHousesScrollPane.repaint();
        manageHousesMainPanel.getUpdateHousePanelButton().addActionListener(new UpdateHousePanelButton());
        manageHousesMainPanel.getShowPeopleButton().addActionListener(new ManagePeopleMainPanelButton());
        manageHousesMainPanel.getShowHouseHelpsButton().addActionListener(new ShowHouseHelpsButton());
    }//GEN-LAST:event_manageHousesPanelButtonActionPerformed

    private void addPersonPanelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addPersonPanelButtonActionPerformed
        manageHousesMainPanel = null;
        addHousePanel = null;
        updateHousePanel = null;
        managePeopleMainPanel = null;
        updatePersonPanel = null;
        addPersonPanel = new AddPersonPanel();
        manageHousesScrollPane.setViewportView(addPersonPanel);
        manageHousesScrollPane.revalidate();
        manageHousesScrollPane.repaint();
    }//GEN-LAST:event_addPersonPanelButtonActionPerformed

    private class UpdateHousePanelButton implements ActionListener {

        public void actionPerformed(ActionEvent e) {
            addHousePanel = null;
            addPersonPanel = null;
            managePeopleMainPanel = null;
            updatePersonPanel = null;
            updateHousePanel = new UpdateHousePanel(HouseManager.getHouse(manageHousesMainPanel.getHouseListSelectedIndex()));
            manageHousesMainPanel = null;
            manageHousesScrollPane.setViewportView(updateHousePanel);
            manageHousesScrollPane.revalidate();
            manageHousesScrollPane.repaint();
            updateHousePanel.getUpdateHousePanelBackButton().addActionListener(new UpdateHousePanelBackButton());
        }

    }

    private class ManagePeopleMainPanelButton implements ActionListener {

        public void actionPerformed(ActionEvent e) {
            addHousePanel = null;
            addPersonPanel = null;
            updateHousePanel = null;
            updatePersonPanel = null;
            managePeopleMainPanel = new ManagePeopleMainPanel(HouseManager.getHouse(manageHousesMainPanel.getHouseListSelectedIndex()));
            manageHousesMainPanel = null;
            manageHousesScrollPane.setViewportView(managePeopleMainPanel);
            manageHousesScrollPane.revalidate();
            manageHousesScrollPane.repaint();
            managePeopleMainPanel.getUpdatePersonPanelButton().addActionListener(new UpdatePersonPanelButton());
            managePeopleMainPanel.getShowHelpsButton().addActionListener(new ShowPersonHelpsButton());
        }

    }

    private class UpdatePersonPanelButton implements  ActionListener {

        public void actionPerformed(ActionEvent e) {
            addHousePanel = null;
            addPersonPanel = null;
            updateHousePanel = null;
            updatePersonPanel = new UpdatePersonPanel(managePeopleMainPanel.getSelectedPerson());
            managePeopleMainPanel = null;
            manageHousesMainPanel = null;
            manageHousesScrollPane.setViewportView(updatePersonPanel);
            manageHousesScrollPane.revalidate();
            manageHousesScrollPane.repaint();
        }

    }

    private class ShowHouseHelpsButton implements ActionListener {

        public void actionPerformed(ActionEvent e) {
            addHousePanel = null;
            addPersonPanel = null;
            updateHousePanel = null;
            houseHelpFinderPanel =new HouseHelpFinderPanel(manageHousesMainPanel.getSelectedHouse());
            updatePersonPanel = null;
            managePeopleMainPanel = null;
            manageHousesMainPanel = null;
            manageHousesScrollPane.setViewportView(houseHelpFinderPanel);
            manageHousesScrollPane.revalidate();
            manageHousesScrollPane.repaint();
        }

    }

    private class ShowPersonHelpsButton implements ActionListener {

        public void actionPerformed(ActionEvent e) {
            addHousePanel = null;
            addPersonPanel = null;
            updateHousePanel = null;
            personHelpFinderPanel =new PersonHelpFinderPanel(managePeopleMainPanel.getSelectedPerson());
            updatePersonPanel = null;
            managePeopleMainPanel = null;
            manageHousesMainPanel = null;
            manageHousesScrollPane.setViewportView(personHelpFinderPanel);
            manageHousesScrollPane.revalidate();
            manageHousesScrollPane.repaint();
        }

    }

    private class AddHousePanelBackButton implements ActionListener {

        public void actionPerformed(ActionEvent e) {
            manageHousesPanelButtonActionPerformed(null);
        }

    }

    private class UpdateHousePanelBackButton implements ActionListener {

        public void actionPerformed(ActionEvent e) {
            manageHousesPanelButtonActionPerformed(null);
        }

    }

    

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton addHousePanelButton;
    private javax.swing.JButton addPersonPanelButton;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JButton manageHousesPanelButton;
    private javax.swing.JScrollPane manageHousesScrollPane;
    // End of variables declaration//GEN-END:variables

}
